package com.user.action

import com.data.annotation.NoargAnnotation
import com.data.annotation.OpenAnnotation
import com.data.bean.Account
import com.data.util.FinalStringUtils
import com.data.util.JsonUtils
import com.user.service.UserAdminService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import javax.servlet.http.HttpServletRequest


@Controller
@OpenAnnotation
@NoargAnnotation
@RequestMapping("/adminIndex/user/")
class UserAdminAction {

    @Autowired
    private var userAdminService: UserAdminService? = null

    /**
     * 进入到首页
     */


    @GetMapping("index")
    fun indexAdminAction(request: HttpServletRequest): String {
        return "WEB-INF/user/index"
    }

    /**
     * 进入到界面的时候的请求链接，统计数据就从这个方法里执行
     */
    @GetMapping("home")
    fun homeAdminAction(request: HttpServletRequest): String {
        return "WEB-INF/user/home"
    }

    /**
     *进入到修改密码
     */
    @GetMapping("change")
    fun changePasswordAction(): String {


        return "WEB-INF/user/password"
    }

    /**
     * 修改密码
     */
    @PostMapping("sumit")
    fun submitChangePasswordAction(request: HttpServletRequest, password: String, oldPassword: String, newPassword: String): String {
        val account = request.session.getAttribute(FinalStringUtils.ACCOUNT) as Account
        var bool = false
        if (password == newPassword)
            bool = userAdminService!!.submitChangePasswordService(account.id, password, oldPassword)
        return if (bool) "redirect:/login" else "WEB-INF/user/password"

    }

}
